{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import random\n",
    "\n",
    "\n",
    "def generate_grade():\n",
    "    # 作业成绩\n",
    "    assignment_grade = random.randint(55, 95)\n",
    "    # 实验成绩\n",
    "    experiment_grade = random.randint(65, 98)\n",
    "    # 课堂练习成绩\n",
    "    class_practice_grade = random.randint(60, 95)\n",
    "    # 期中考试成绩\n",
    "    midterm_grade = random.randint(62, 98)\n",
    "    # 期末考试成绩\n",
    "    final_exam_grade = random.randint(65, 100)\n",
    "\n",
    "    # 计算总评成绩\n",
    "    total_grade = (assignment_grade * 0.2 + experiment_grade * 0.1 + class_practice_grade * 0.1 +\n",
    "                   midterm_grade * 0.2 + final_exam_grade * 0.4)\n",
    "\n",
    "    # 课程目标 1 达成情况估算\n",
    "    if total_grade >= 85 and (assignment_grade >= 80 and class_practice_grade >= 80 and midterm_grade >= 80):\n",
    "        goal1_achievement = \"优秀\"\n",
    "    elif 75 <= total_grade < 85 and (assignment_grade >= 70 and class_practice_grade >= 70 and midterm_grade >= 70):\n",
    "        goal1_achievement = \"良好\"\n",
    "    elif 60 <= total_grade < 75 and (assignment_grade >= 60 and class_practice_grade >= 60 and midterm_grade >= 60):\n",
    "        goal1_achievement = \"中等\"\n",
    "    else:\n",
    "        goal1_achievement = \"不合格\"\n",
    "\n",
    "    # 课程目标 2 达成情况估算\n",
    "    if total_grade >= 80 and (experiment_grade >= 80 and final_exam_grade >= 80):\n",
    "        goal2_achievement = \"优秀\"\n",
    "    elif 70 <= total_grade < 80 and (experiment_grade >= 70 and final_exam_grade >= 70):\n",
    "        goal2_achievement = \"良好\"\n",
    "    elif 60 <= total_grade < 70 and (experiment_grade >= 60 and final_exam_grade >= 60):\n",
    "        goal2_achievement = \"中等\"\n",
    "    else:\n",
    "        goal2_achievement = \"不合格\"\n",
    "\n",
    "    # 课程目标 3 达成情况估算\n",
    "    if total_grade >= 80:\n",
    "        goal3_achievement = \"优秀\"\n",
    "    elif 70 <= total_grade < 80:\n",
    "        goal3_achievement = \"良好\"\n",
    "    elif 60 <= total_grade < 70:\n",
    "        goal3_achievement = \"中等\"\n",
    "    else:\n",
    "        goal3_achievement = \"不合格\"\n",
    "\n",
    "    return [assignment_grade, experiment_grade, class_practice_grade, midterm_grade, final_exam_grade, total_grade,\n",
    "            goal1_achievement, goal2_achievement, goal3_achievement]\n",
    "\n",
    "\n",
    "# 生成 30 行数据\n",
    "data = []\n",
    "for _ in range(30):\n",
    "    data.append(generate_grade())\n",
    "\n",
    "# 创建 DataFrame\n",
    "df = pd.DataFrame(data, columns=[\"作业成绩\", \"实验成绩\", \"课堂练习成绩\", \"期中考试成绩\", \"期末考试成绩\", \"总评成绩\", \"课程目标 1 达成情况\",\n",
    "                                 \"课程目标 2 达成情况\", \"课程目标 3 达成情况\"])\n",
    "\n",
    "# 保存到 Excel 文件\n",
    "df.to_excel(\"linear_algebra_grades.xlsx\", index=False)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "base",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
